package com.kehutong.department.entity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.coraframework.bean.valid.CheckField;
import org.coraframework.orm.Entity;
import org.coraframework.orm.FilterAble;
import org.coraframework.orm.annotation.Column;
import org.coraframework.orm.annotation.Table;
import org.coraframework.orm.annotation.UnSave;
import org.coraframework.orm.util.IDType;
import com.kehutong.common.entity.ITree;

/**
 * 企业微信组织架构
 *
 * @author liuzhen (liuxing521a@163.com)
 * @createTime 2020年5月19日 下午5:30:00
 */
@Table(value="t_department", comment="部门", multi=true, idType=IDType.TIMESTAMP,isSyncGenerateTable = true)
public class Department extends Entity implements ITree<Department>, FilterAble {

	private static final long serialVersionUID = -6907983875624176462L;

	protected Department(String id) {
		super(id);
		this.sort = 30;
	}

	@Column(comment="上级id")
	private String parent_id;
	
	@Column(comment="所有上级id")
	private List<String> parent_ids;
	
	@CheckField("部门名称不能为空")
	@Column(length=64, comment="部门名称")
	private String name;
	
	@Column(comment="员工数量")
	private int memCount;

	@Column(comment="主管id")
	private List<String> employeeIds;

	@Column(comment="主管名称")
	private List<String> employeeNames;
	
	@Column(comment="排序")
	private int sort;

	@Column(comment="逻辑删除")
	private boolean deleted;

	@Column(length=64, comment="部门名称")
	private String thirdName;

	@UnSave private List<Department> childList;

	@UnSave private String parent_names;

	@UnSave private List<String> parentNames;
	
	@Override
	public String getPid() {
		return parent_id;
	}

	public String getParent_id() {
		return parent_id;
	}

	public void setParent_id(String parent_id) {
		this.parent_id = parent_id;
	}

	public List<String> getParent_ids() {
		return parent_ids;
	}

	public void setParent_ids(List<String> parent_ids) {
		this.parent_ids = parent_ids;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	@Override
	public List<Department> getChildList() {
		if (Objects.isNull(childList)) {
			return Collections.emptyList();
		}
		
		return childList;
	}

	@Override
	public void setChildList(List<Department> childList) {
		this.childList = childList;
	}

	@Override
	public void addChild(Department child) {
		if (Objects.isNull(childList)) {
			childList = new ArrayList<>();
		}
		
		childList.add(child);
	}

	public List<String> getEmployeeIds() {
		return employeeIds;
	}

	public void setEmployeeIds(List<String> employeeIds) {
		this.employeeIds = employeeIds;
	}

	public List<String> getEmployeeNames() {
		return employeeNames;
	}

	public void setEmployeeNames(List<String> employeeNames) {
		this.employeeNames = employeeNames;
	}

	public String getParent_names() {
		return parent_names;
	}

	public void setParent_names(String parent_names) {
		this.parent_names = parent_names;
	}

	public int getMemCount() {
		return memCount;
	}

	public void setMemCount(int memCount) {
		this.memCount = memCount;
	}

	public String getThirdName() {
		return thirdName;
	}

	public void setThirdName(String thirdName) {
		this.thirdName = thirdName;
	}

	public List<String> getParentNames() {
		return parentNames;
	}

	public void setParentNames(List<String> parentNames) {
		this.parentNames = parentNames;
	}

	@Override
	public String offerFieldName() {
		return "parent_id";
	}

	@Override
	public String offerTreeFieldName() {
		return "parent_ids";
	}
}
